package com.ztgf.shopping.api.cms.epg;


import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.common.utils.CustomizeUtil;
import com.ztgf.shopping.models.bo.epg.EpgConsultingServiceQueryBO;
import com.ztgf.shopping.models.bo.epg.EpgConsultingServiceSaveBO;
import com.ztgf.shopping.models.dto.epg.EpgConsultingServiceDTO;
import com.ztgf.shopping.models.service.epg.IEpgConsultingService;
import com.ztgf.shopping.models.vo.epg.EpgConsultingServicePageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/cms/epgConsultingService")
@Api(value = "EpgConsultingServiceController", tags = "首页咨询表CMS接口")
public class EpgConsultingServiceController {


    @DubboReference
    private IEpgConsultingService epgConsultingService;

    @PostMapping("/add")
    @ApiOperation(value = "添加首页咨询表", notes = "添加首页咨询表")
    public Result<?> add(EpgConsultingServiceSaveBO bo) {
        return epgConsultingService.add(bo);
    }


    @PostMapping("/queryPageList")
    @ApiOperation(value = "首页咨询列表", notes = "首页咨询列表")
    public Result<?> queryPageList(EpgConsultingServiceQueryBO queryBO) {
        Page<EpgConsultingServicePageVO> page = epgConsultingService.queryPageList(queryBO);
        return new Result<>(page);
    }

    @PostMapping("/getById")
    @ApiOperation(value = "根据id获取详情", notes = "根据id获取详情")
    public Result<?> getById(Long id) {
        if (id == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        EpgConsultingServiceDTO dto = epgConsultingService.selectById(id);
        return new Result<>(dto);
    }

    @PostMapping("/updateById")
    @ApiOperation(value = "修改首页咨询", notes = "修改首页咨询")
    public Result<?> updateById(EpgConsultingServiceSaveBO updateBo) {
        if (updateBo.getId() == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        return epgConsultingService.update(updateBo);
    }

    @PostMapping("/deleteById")
    @ApiOperation(value = "软删除接口", notes = "软删除接口")
    public Result<?> deleteById(Long id) {
        if (id == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        return epgConsultingService.delete(id);
    }

    @PostMapping("/updateIsTop")
    @ApiOperation(value = "修改是否置顶", notes = "修改是否置顶")
    public Result<?> updateIsTop(Long id) {
        if (id == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        return epgConsultingService.updateIsTop(id);
    }

    @PostMapping("/updateIsHot")
    @ApiOperation(value = "修改是否热标签", notes = "修改是否热标签")
    public Result<?> updateIsHot(Long id) {
        if (id == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        return epgConsultingService.updateIsHot(id);
    }

    @PostMapping("/updateSort")
    @ApiOperation(value = "修改排序号", notes = "修改排序号")
    public Result<?> updateSort(Long id, Integer sort) {
        if (id == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        return epgConsultingService.updateSort(id, sort);
    }

    @PostMapping("/deleteBatch")
    @ApiOperation(value = "批量删除", notes = "批量删除")
    public Result<?> deleteBatch(String ids) {
        if (CustomizeUtil.strIsNull(ids)) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        return epgConsultingService.deleteBatch(ids);
    }

    @PostMapping("/updateIsPush")
    @ApiOperation(value = "修改是否隐藏", notes = "修改是否隐藏")
    public Result<?> updateIsPush(Long id) {
        if (id == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        }
        boolean flag = epgConsultingService.updateIsPush(id);
        if (flag) {
            return new Result<>(CodeEnum.SUCCESS);
        } else {
            return new Result<>(CodeEnum.FAIL);
        }
    }
}
